package com.xia.service.impl;

import com.xia.mapper.BookMapper;
import com.xia.pojo.Book;
import com.xia.service.BookService;
import com.xia.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    public BookMapper bookMapper;

    @Override
    public PageBean<Book> queryByPage(Map<String, Object> map) {

        PageBean<Book> pageBean = new PageBean<>((Integer) map.get("pageNo"), (Integer) map.get("pageSize"));
        // 获取开始检索
        Integer startIndex = pageBean.getStartIndex();
        map.put("startIndex", startIndex);
        List<Book> bookList = bookMapper.queryByPage(map);
        pageBean.setData(bookList);
        // 数据总条数
        Integer totalSize = bookMapper.queryCount(map);
        pageBean.setTotalSize(totalSize);

        return pageBean;
    }

    @Override
    public Book queryById(Integer bookId) {
        return bookMapper.queryById(bookId);
    }

    @Override
    public void updateBookInfo(Book book) {
        bookMapper.updateBookInfo(book);
    }

    @Override
    public void delBookById(Integer bookId) {
        bookMapper.delBookById(bookId);
    }

    @Override
    public void addBook(Book book) {
        bookMapper.addBook(book);
    }
}
